home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0011_PATCHEXE.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  76 lines

  1. {
  2. >If this cannot be done, then hhow can one include a pcx directly inside
  3. >the compiled File???
  4.  
  5.   There's a trick to do that :
  6.   Suppose your Program is called PROG.EXE and your PCX File IMAGE.PCX
  7.  
  8.   After each compile of PROG.EXE, do :
  9.   COPY /B PROG.EXE+IMAGE.PCX
  10.  
  11.   Then, when you want to display the PCX, open the EXE File, read it's
  12.   header :
  13. }
  14.  
  15. Function GetExeSize(ExeName:String; Var TotSize,Expect:LongInt):Boolean;
  16. { returns True if EXE is already bind }
  17. Type
  18.   ExeHeaderRec = Record {Information describing EXE File}
  19.     Signature         : Word; {EXE File signature}
  20.     LengthRem         : Word; {Number of Bytes in last page of EXE image
  21.     LengthPages       : Word; {Number of 512 Byte pages in EXE image}
  22.     NumReloc          : Word; {Number of relocation items}
  23.     HeaderSize        : Word; {Number of paraGraphs in EXE header}
  24.     MinHeap,MaxHeap   : Word; {ParaGraphs to keep beyond end of image}
  25.     StackSeg,StackPtr : Word; {Initial SS:SP, StackSeg relative to image
  26.     CheckSum          : Word; {EXE File check sum, not used}
  27.     IpInit, CodeSeg   : Word; {Initial CS:IP, CodeSeg relative to image
  28.     RelocOfs          : Word; {Bytes into EXE For first relocation item}
  29.     OverlayNum        : Word; {Overlay number, not used here}
  30.   end;
  31.  
  32. Var
  33.   ExeF : File;
  34.   ExeHeader : ExeHeaderRec;
  35.   ExeValue : LongInt;
  36.   count : Word;
  37.  
  38. begin
  39.   TotSize:=0; Expect:=0;
  40.   Assign(ExeF,ExeName); Reset(ExeF,1);
  41.   if IoResult=0 then
  42.   begin
  43.     TotSize:=FileSize(ExeF);
  44.     BlockRead(ExeF,ExeHeader,SizeOf(ExeHeaderRec),Count);
  45.     With ExeHeader do
  46.     if Signature=$5A4D then
  47.     begin
  48.       if LengthRem=0 then
  49.         ExeValue:=LongInt(LengthPages) shl 9
  50.       else
  51.         ExeValue:=(LongInt(Pred(LengthPages)) shl 9)
  52.       Expect:=ExeValue;
  53.     end;
  54.   end;
  55.   Close(ExeF);
  56.   GetExeSize:=(TotSize<>Expect);
  57. end;
  58.  
  59. {
  60.   If GetExeSize returns True, your PCX has been placed at the end of the
  61.   EXE (you did not forget :)) and all you have to do next is skip the
  62.   Program itself : Seek(ExeF,Expect);
  63.  
  64.   Then starts your PCX. If you know in advance the sizes of the PCX
  65.   File, you can place any data you want (including lots of PCX) at the
  66.   end of your EXE.
  67.  
  68.   This example is taken from a Unit I wrote a long time ago (was called
  69.   Caravane) and it worked very well. I accessed the end of my exe File
  70.   like a normal Typed File. Quite funny but I do not use this anymore.
  71.   Note that you can LzExe or Pklite the EXE part (not the PCX one). You
  72.   can DIET both parts With the resident version.
  73.  
  74.   I hope the Function GetExeSize is not copyrighted since it is much too
  75.   commented to be one of my work :)
  76.